/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.renderer;

import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Font;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.list.ListCellRenderer;
import edu.mobbuzz.util.string.MenuString;
import java.io.IOException;

/**
 *
 * @author dailicious
 */
public class MenuRenderer extends Container implements ListCellRenderer{
    private Label label = new Label("");
    private Label pic = new Label("");
    private Image icon = null;
    private Label focus = new Label("");

    public MenuRenderer(){
        setLayout(new BorderLayout());
        addComponent(BorderLayout.WEST, pic);
        Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));

        label.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        label.getStyle().setBgTransparency(0);
        label.getStyle().setMargin(0, 0, 0, 0);

        pic.getStyle().setBgTransparency(0);
        cnt.addComponent(label);

        addComponent(BorderLayout.CENTER, cnt);
        focus.getStyle().setBgTransparency(100);
        focus.getStyle().setBgColor(0xCCCCCC);
    }

    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
        
        String _value = (String) value;
        label.setText(_value);

        try {
            if(_value.equals(MenuString.INBOX)){
                icon = Image.createImage("/icons/mail.png");
            }else if(_value.equals(MenuString.OUTBOX)){
                icon = Image.createImage("/icons/mail_send.png");
            }else if(_value.equals(MenuString.RSSCHANNEL)){
                icon = Image.createImage("/icons/rss.png");
            }else if(_value.equals(MenuString.CATEGORY)){
                icon = Image.createImage("/icons/favorite.png");
            }else if(_value.equals(MenuString.CONTACT)){
                icon = Image.createImage("/icons/address_book.png");
            }
            
        } catch (IOException ex) {
            ex.printStackTrace();
        }


        pic.setIcon(icon);

        return this;
    }

    public Component getListFocusComponent(List list) {
        return focus;
    }

}
